/**
 * @author gaopeng
 * @date 2019/12/12 11:23 下午
 */
public class Mediator extends AbstractMediator {
    @Override
    protected void execute(String method, Object ...obj) {
        if("purchase.buy".equals(method)){
            this.buyComputer((int)obj[0]);
        }else if("sale.sell".equals(method)){
            this.saleComputer((int)obj[0]);
        }else if("sale.offsell".equals(method)){
            this.offSell();
        }else if("stock.clear".equals(method)){
            this.clearStock();
        }
    }

    private void buyComputer(int number) {
        int saleStatus = super.sale.getSaleState();
        if(saleStatus>80){
            System.out.println("采购电脑"+number+"台");
            this.stock.increase(number);
        }
    }

    private void saleComputer(int number){
        //库存数量不够销售
        if(super.stock.getStockNumber()<number){
            super.purchase.buyComputer(number);
        }
        super.stock.decrease(number);
    }

    private void offSell(){
        System.out.println("折价销售电脑"+super.stock.getStockNumber()+"台");
    }

    private void clearStock(){
        //要求清仓销售
        super.sale.offSale();
        //要求采购人员不要采购
        super.purchase.refuseBuyComputer();
    }
}
